(function () {
    const curdFilter = {
        title: "",
        name: "curdFilter_1",
        body: [
            {
                type: "group",
                mode: "horizontal",//水平模式
                body: [
                    {
                        label: "编号",
                        type: "input-text",
                        name: "code",
                        clearable: true
                    },
                    {
                        label: "链接地址",
                        type: "input-text",
                        name: "url",
                        clearable: true
                    },
                    {
                        label: "用户名",
                        type: "input-text",
                        name: "username",
                        clearable: true
                    }
                ]
            }
        ],
        actions: [
            {
                type: "button",
                label: "新增",
                actionType: "dialog",
                reload: "crud_1",
                dialog: {
                    title: "新增数据库链接",
                    size: "lg",
                    body: {
                        type: "form",
                        api: "/api/dataSource/add",
                        body: [
                            {
                                label: "编号",
                                type: "input-text",
                                name: "code",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "URL",
                                type: "input-text",
                                name: "url",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "用户名",
                                type: "input-text",
                                name: "username",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "密码",
                                type: "input-password",
                                name: "password",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "备注",
                                type: "input-text",
                                name: "remark",
                                clearable: true
                            }
                        ]
                    },
                    actions: [
                        {
                            type: "action",
                            actionType: "ajax",
                            label: "测试连接",
                            level: "warning",
                            api: "post:/api/dataSource/testConnect",
                            messages: {
                                success: "连接成功！",
                                failed: "连接失败了呢。"
                            }
                        },
                        {
                            type: "reset",
                            label: "重置"
                        },
                        {
                            type: "submit",
                            label: "保存",
                            level: "primary"
                        },
                    ]
                },
            },
            {
                type: "reset",
                label: "重置"
            },
            {
                type: "submit",
                level: "primary",
                label: "查询"
            }
        ]
    }

    const itemActions = [
        {
            type: "button",
            icon: "fa fa-pencil",
            tooltip: "编辑",
            actionType: "dialog",
            dialog: {
                size: "lg",
                title: "",
                name: "edit_dialog_1",
                body: [
                    {
                        type: "form",
                        name: "form_1",
                        initApi: "/api/dataSource/findByCode",
                        api: "post:/api/dataSource/edit/${id}",
                        body: [
                            {
                                label: "编号",
                                type: "input-text",
                                name: "code",
                                clearable: true,
                                disabled: true
                            },
                            {
                                label: "URL",
                                type: "input-text",
                                name: "url",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "用户名",
                                type: "input-text",
                                name: "username",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "密码",
                                type: "input-password",
                                name: "password",
                                clearable: true,
                                required: true
                            },
                            {
                                label: "备注",
                                type: "input-text",
                                name: "remark",
                                clearable: true
                            }
                        ]
                    }
                ],
                actions: [
                    {
                        type: "button",
                        actionType: "ajax",
                        label: "测试连接",
                        level: "warning",
                        api: "post:/api/dataSource/testConnect",
                        messages: {
                            success: "连接成功！",
                            failed: "连接失败了呢。"
                        }
                    },
                    {
                        type: "submit",
                        label: "保存",
                        level: "primary"
                    }
                ]
            }
        },
        {
            type: "button",
            icon: "fa fa-trash",
            tooltip: "删除",
            actionType: "ajax",
            confirmText: "您确认要删除数据库配置$id吗?",
            api: "/api/dataSource/remove/$id"
        }
    ]

    const crud = {
        type: "crud",
        name: "crud_1",
        api: "post:/api/dataSource/findByCondition",
        orderField: "id",
        affixHeader: true,//开启固定表头功能
        filter: curdFilter,
        mode: "cards",
        card: {
            body: [
                {
                    label: "编号",
                    name: "code"
                },
                {
                    label: "URL",
                    name: "url"
                },
                {
                    label: "用户名",
                    name: "username"
                },
                {
                    label: "密码",
                    name: "password"
                },
                {
                    label: "备注",
                    name: "remark"
                }
            ],
            actions: itemActions
        }
    }

    const response = {
        data: {
            type: "page",
            title: "",
            body: [crud]
        },
        status: 0
    }

    window.jsonpCallback && window.jsonpCallback(response);
})();
